//
//  UTabBarController.swift
//  u17Comic
//
//  Created by hujian on 2019/7/9.
//  Copyright © 2019 hujian. All rights reserved.
//

import UIKit

class UTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        UITabBar.appearance().tintColor = UIColor.theme
        
        /// 更新
        let classVC1 = UpdateViewController()
        addChildViewController(classVC1,
                               title: "更新",
                               image: UIImage(named: "tab_class"),
                               selectedImage: UIImage(named: "tab_class_S"))
        
        /// 发现
        let classVC2 = DiscoveryViewController()
        addChildViewController(classVC2,
                               title: "发现",
                               image: UIImage(named: "tab_class"),
                               selectedImage: UIImage(named: "tab_class_S"))
        
        /// 书架
        let classVC3 = LibraryViewController()
        addChildViewController(classVC3,
                               title: "书架",
                               image: UIImage(named: "tab_class"),
                               selectedImage: UIImage(named: "tab_class_S"))
        
        /// 我的
        let classVC4 = MineViewController()
        addChildViewController(classVC4,
                               title: "我的",
                               image: UIImage(named: "tab_class"),
                               selectedImage: UIImage(named: "tab_class_S"))
        
    }
    
    func addChildViewController(_ childController: UIViewController, title:String?, image:UIImage? ,selectedImage:UIImage?) {
        
        childController.title = title
        childController.tabBarItem = UITabBarItem(title: nil,
                                                  image: image?.withRenderingMode(.alwaysOriginal),
                                                  selectedImage: selectedImage?.withRenderingMode(.alwaysOriginal))
        
        if UIDevice.current.userInterfaceIdiom == .phone {
            childController.tabBarItem.imageInsets = UIEdgeInsets(top: 6, left: 0, bottom: -6, right: 0)
        }
        addChild(HJNavigationController(rootViewController: childController))
    }


}


extension UTabBarController {
    override var preferredStatusBarStyle: UIStatusBarStyle {
        guard let select = selectedViewController else { return .lightContent }
        return select.preferredStatusBarStyle
    }
}
